package com.mpgame.core.model;

import java.util.ArrayList;
import java.util.List;

import com.mpgame.core.effect.Effect;
import com.mpgame.core.utils.MReport;
import com.mpgame.core.utils.MRules;

import lombok.Data;

@Data
public class Skill {
    private final int familyId, power, priority, maxPp;
    private final double accuracy;
    private final SkillType skillType;
    private int curPp;
    private final List<Effect> effect_to_self, effect_to_opponent;

    private String identifier;

    public Skill(int familyId, int power, int priority, int maxPp, double accuracy, SkillType skillType, List<Effect> effect_to_self, List<Effect> effect_to_opponent) {
        this.familyId = familyId;
        this.power = power;
        this.priority = priority;
        this.maxPp = maxPp;
        this.accuracy = accuracy;
        this.effect_to_self = effect_to_self;
        this.effect_to_opponent = effect_to_opponent;
        this.skillType = skillType;

        this.curPp = maxPp;
    }

    public boolean doRound(Monster mOwner) {
        boolean hasSkillDamage = false;
        if (accuracy == 1.0 || Math.random() < accuracy * MRules.getReinforcedValueDouble(mOwner.getCurAccuracy(), mOwner.getCurReinforces().get("accuracy"))) {
            MReport.Report(mOwner.getIdentifier() + "的技能 " + mOwner.getCurSkill().getIdentifier() + " 命中了！");
            if (skillType == SkillType.MELEE) {
                mOwner.getCurOpponent().takeHurt(new Damage(DamageType.MELEE, MRules.getReinforcedValue(mOwner.getCurMeleeAtk() * this.power, mOwner.getCurReinforces().get("meleeAtk"))));
                hasSkillDamage = true;
            } else if (skillType == SkillType.MAGIC) {
                mOwner.getCurOpponent().takeHurt(new Damage(DamageType.MAGIC, MRules.getReinforcedValue(mOwner.getCurMagicAtk() * this.power, mOwner.getCurReinforces().get("magicAtk"))));
                hasSkillDamage = true;
            }
            if (this.effect_to_self != null) {
                for (Effect e : effect_to_self)
                    e.apply(mOwner);
            }
            if (this.effect_to_opponent != null) {
                for (Effect e : effect_to_opponent)
                    e.apply(mOwner.getCurOpponent());
            }
        }
        else{
            MReport.Report(mOwner.getIdentifier() + "的技能 " + mOwner.getCurSkill().getIdentifier() + " MISS！（未命中）");
        }
        curPp--;
        return hasSkillDamage;
    }
}
